package com.xoa.controller.attend;

import com.xoa.model.attend.AttendSet;
import com.xoa.model.users.Users;
import com.xoa.service.attend.AttendSetService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.dataSource.ContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * 考勤类型设置
 */
@Controller
@RequestMapping("/attendSet")
public class AttendSetController {

    @Autowired
    private AttendSetService attendSetService;

    /**
     * 添加考勤类型
     */
    @RequestMapping(value = "/newAttendSet", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ToJson<AttendSet> newAttendSet(AttendSet attendSet,HttpServletRequest request) {
        return  attendSetService.newAttendSet(attendSet,request);
    }

    /**
     * 修改考勤类型
     */
    @RequestMapping(value = "/updateAttendSet", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ToJson<AttendSet> updateAttendSet(AttendSet attendSet){
        return  attendSetService.updateAttendSet(attendSet);
    }

    /**
     * 查询全部考勤类型
     */
    @RequestMapping(value = "/selsectAttendSet",produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ToJson<AttendSet> selsectAttendSet(HttpServletRequest request){
        ContextHolder.setConsumerType("xoa" + (String) request.getSession().getAttribute("loginDateSouse"));
        return  attendSetService.selectAttendSet();
    }

    /**
     * 根据ID查详情
     */
    @RequestMapping(value = "/queryAttendSetId",produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ToJson<AttendSet> queryAttendSetId(HttpServletRequest request,Integer sid){
        return  attendSetService.queryAttendSetId(sid,request);
    }

    /**
     * 删除考勤类型
     * @param request
     * @param sid
     * @return
     */
    @RequestMapping(value = "/delAttendSetbyId",produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ToJson<AttendSet> delAttendSetbyId(HttpServletRequest request,Integer sid){
        ContextHolder.setConsumerType("xoa"+ (String) request.getSession().getAttribute("loginDateSouse"));
        return  attendSetService.delAttendSetbyId(sid);
    }

//    考勤管理
    @RequestMapping("/attendManage")
    public String attendManage(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/index";
    }
//   考勤设置
    @RequestMapping("/attendSetting")
    public String attendSetting(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/attendSetting";
    }
//   地图
    @RequestMapping("/attendMap")
    public String attendMap(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/attendMap";
    }
//    免签人员
    @RequestMapping("/noSignPersonnel")
    public String noSignPersonnel(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/noSignPersonnel";
    }
//    节假日设置
    @RequestMapping("/holidaySetting")
    public String holidaySetting(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/holidaySetting";
    }
//    考勤机设置
    @RequestMapping("/machineSetting")
    public String machineSetting(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/machineSetting";
    }
    //    统计规则设置
    @RequestMapping("/statisticalRuleSetting")
    public String statisticalRuleSetting(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/statisticalRuleSetting";
    }
    //    年假设置
    @RequestMapping("/annualLeaveSetting")
    public String annualLeaveSetting(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/annualLeaveSetting";
    }
    //    代考勤设置
    @RequestMapping("/generationSetting")
    public String generationSetting(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/generationSetting";
    }
//    节假日设置
    @RequestMapping("/takeWorking")
    public String takeWorking(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/attend/attendManagement/takeWorking";
    }

}
